package com.ruoyi.business.appuser.controller;

import com.ruoyi.business.appuser.service.IDeviceService;
import com.ruoyi.business.appuser.vo.DeviceVo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author Tellsea
 * @date 2025-05-22
 */
@Api(tags = "【请填写功能名称】Controller")
@RestController
@RequestMapping("/business/device")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class DeviceController extends BaseController {

    private final IDeviceService deviceService;

    @ApiOperation("查询【请填写功能名称】列表")
//    @PreAuthorize("@ss.hasPermi('business:device:list')")
    @GetMapping("/list")
    public TableDataInfo<DeviceVo> list(DeviceVo entity) {
        return deviceService.queryList(entity);
    }

    @ApiOperation("查询【请填写功能名称】所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(DeviceVo entity) {
        return AjaxResult.success("查询成功", deviceService.queryAll(entity));
    }

    @ApiOperation("导出【请填写功能名称】列表")
//    @PreAuthorize("@ss.hasPermi('business:device:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceVo entity) {
        List<DeviceVo> list = deviceService.queryAll(entity);
        ExcelUtil<DeviceVo> util = new ExcelUtil<>(DeviceVo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    @ApiOperation("获取【请填写功能名称】详细信息")
//    @PreAuthorize("@ss.hasPermi('business:device:query')")
    @GetMapping(value = "/getInfo/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) {
        return AjaxResult.success("查询成功", deviceService.queryById(deviceId));
    }

    @ApiOperation("新增【请填写功能名称】")
//    @PreAuthorize("@ss.hasPermi('business:device:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody DeviceVo entity) {
        return toAjax(deviceService.save(entity));
    }

    @ApiOperation("修改【请填写功能名称】")
//    @PreAuthorize("@ss.hasPermi('business:device:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody DeviceVo entity) {
        return toAjax(deviceService.updateById(entity));
    }

    @ApiOperation("删除【请填写功能名称】")
//    @PreAuthorize("@ss.hasPermi('business:device:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds) {
        return toAjax(deviceService.removeByIds(Arrays.asList(deviceIds)) ? 1 : 0);
    }

//    @PreAuthorize("@ss.hasPermi('business:device:query')")
    @GetMapping(value = "/getDevice/{deviceName}")
    public AjaxResult getInfo(@PathVariable("deviceName") String deviceName) {

        List<DeviceVo> deviceVo = deviceService.queryByDeviceName(deviceName);
        return AjaxResult.success("查询成功", deviceVo);
    }
}
